import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../common.dart';

class Details extends StatefulWidget {
  Details({super.key});
  @override
  State<Details> createState() => _QGRulePageState();
}

class _QGRulePageState extends State<Details> {
  final uuid = Get.parameters['uuid'];
  Map info = {};
  Map materials = {};
  List detailimages = [];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getData(url: '/third/$uuid').then((res) {
      info = res;
      materials = res['materials'];
      detailimages = res['detail_images'];
      setState(() {});
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Color(0XFFFFFFFF),
        centerTitle: true,
        leading: buildBackButton(context),
      ),
      backgroundColor: Color(0xFFFFFFFF),
      body: Column(
        children: [
          Expanded(
            child: ListView(
              padding: EdgeInsets.symmetric(horizontal: 15),
              children: [
                Stack(
                  children: [
                    wImage(url: '${info['thumb']}', borderRadius: 10),
                    // Positioned(
                    //   top: 10,
                    //   left: 10,
                    //   child: wImage(url: 'aaa', width: 50),
                    // ),
                  ],
                ),
                SizedBox(height: 15),
                wText(text: '可兑换${info['stock']}份', size: 14, color: '6828FF'),
                wText(text: '${info['title']}', bold: true, size: 22),
                SizedBox(height: 15),
                Container(
                  padding: EdgeInsets.symmetric(horizontal: 12, vertical: 10),
                  decoration: BoxDecoration(
                    color: Color(0XFFF8F9FD),
                    borderRadius: BorderRadius.circular(10),
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      wText(text: '消耗藏品', size: 14),
                      SizedBox(height: 10),
                      Row(
                        children: [
                          wImage(
                            url: '${materials['thumb']}',
                            width: 45,
                            height: 45,
                            borderRadius: 5,
                          ),
                          SizedBox(width: 10),
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              wText(text: '${materials['title']}'),
                              SizedBox(height: 5),
                              // wText(text: '￥93329.00', size: 14, bold: true),
                            ],
                          ),
                        ],
                      ),
                      Container(
                        margin: EdgeInsets.only(top: 10),
                        padding: EdgeInsets.symmetric(
                          horizontal: 10,
                          vertical: 10,
                        ),
                        decoration: BoxDecoration(
                          color: Color(0XFFF0E2FF),
                          borderRadius: BorderRadius.circular(10),
                        ),
                        child: wText(
                          text: '稀有兑换有一定概率兑换失败，兑换失败后消耗的藏品将原路返还至您的钱包账户',
                        ),
                      ),
                    ],
                  ),
                ),
                SizedBox(height: 20),
                Row(
                  children: [
                    wText(text: '商品类型', color: '878b95', size: 14),
                    SizedBox(width: 20),
                    wText(text: '实物商品', size: 14),
                  ],
                ),
                SizedBox(height: 20),
                Row(
                  children: [
                    wText(text: '兑换类型', color: '878b95', size: 14),
                    SizedBox(width: 20),
                    wText(text: '普通兑换', size: 14),
                  ],
                ),
                SizedBox(height: 20),
                Row(
                  children: [
                    wText(text: '兑换须知', color: '878b95', size: 14),
                    SizedBox(width: 20),
                    wText(text: '兑换成功后不支持退换货', size: 14),
                  ],
                ),
                SizedBox(height: 20),
                Row(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    wText(text: '兑换说明', color: '878b95', size: 14),
                    SizedBox(width: 20),
                    Expanded(
                      child: wText(
                        text: '可兑换规格仅供参考，实际库存以用户兑换情况为准，数据可能存在延迟，敬请理解。',
                        size: 14,
                      ),
                    ),
                  ],
                ),
                SizedBox(height: 25),

                wText(text: '商品信息', size: 18, bold: true),
                SizedBox(height: 10),

                for (var itemv in detailimages.asMap().entries)
                  wImage(url: '${itemv.value}', borderRadius: 10),
              ],
            ),
          ),
          SizedBox(height: 15),

          wCon(
            text: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [wText(text: '立即兑换', color: 'FFFFFF', size: 18)],
            ),
            click: () {
              toNamed('/home/exchange/order?uuid=$uuid');
            },
          ),
          SizedBox(height: 15),
        ],
      ),
    );
  }
}
